package com.cyzy.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cyzy.domain.bean.TAgent;
import com.cyzy.domain.dto.LoginDto;
import com.cyzy.domain.dto.ResponseData;
import com.cyzy.service.TAgentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * TODO
 *
 * @author Honarly
 * @date 2024.11.12
 */
@RestController
@RequestMapping("/agent")
@RequiredArgsConstructor
public class TAgentController {

    private final TAgentService tAgentService;

    @PostMapping("/login")
    public ResponseData login(@RequestBody LoginDto login, HttpSession session) {
        LambdaQueryWrapper<TAgent> qw = new LambdaQueryWrapper<>();
        qw.eq(TAgent::getAgentAccount, login.getAccount()).eq(TAgent::getAgentPassword, login.getPassword());
        TAgent one = tAgentService.getOne(qw);
        if (one == null) {
            return ResponseData.error("账号或密码错误");
        }else {
            return ResponseData.success("登录成功", one.getAgentId(), 1);
        }
    }
}
